package com.test.kotlin07

interface Production<out T>{//协变
    fun product():T
}

interface Consumer<in T>{//逆变
    fun consume(item:T)
}

interface ProductionConsumer<T>{
    fun product():T
    fun consume(item:T)
}

open class Food

open class FastFood:Food()

open class Burger:FastFood()

class FoodStore:Production<Food>{
    override fun product(): Food {
        println("Produce food")
        return Food()
    }
}

class FoastFoodStore:Production<FastFood>{
    override fun product(): FastFood {
        println("Produce FoastFoodStore")
        return FastFood()
    }
}


class BurgerStore:Production<Burger>{
    override fun product(): Burger {
        println("Produce Burger")
        return Burger()
    }
}

class Everybody:Consumer<Food>{
    override fun consume(item:Food) {
        println("Eat food")
    }
}

class Modernbody:Consumer<FastFood>{
    override fun consume(item:FastFood) {
        println("Eat FastFood")
    }
}

class American:Consumer<Burger>{
    override fun consume(item:Burger) {
        println("Eat Burger")
    }
}




fun main() {
    val p1:Production<Food> = FoodStore()
    //子类对象可以赋值给父类
    val p2:Production<Food> = FoastFoodStore()
    p1.product()
    p2.product()


    val c1:Consumer<Burger> = Everybody()
    val c2:Consumer<Burger> = Modernbody()
    val c3:Consumer<Burger> = American();
    c1.consume(Burger())
    c2.consume(Burger())
    c3.consume(Burger())
}
